<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!--   引入 echarts.js -->
    <script src="/page/echarts.js"></script>
    <!-- 引入 jQuery.js -->
    <script src="/page/jquery-3.7.0.min.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
<div id="main" style="width: 1000px;height:550px;"></div>
<script type="text/javascript">
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option;

    $.get('http://localhost:8080/ChapterNumAvg', function (data) {
        var novelNames = data.map(function (item) {
            return item.novelName;
        });
        var novelChapters = data.map(function (item) {
            return item.novelChapter;
        });
        var numAvgs = data.map(function (item) {
            return item.numAvg;
        });

        var option = {
            title: {
                text: '小说每章平均字数Top',
                left: 'center'
            },
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross'
                }
            },
            xAxis: {
                type: 'category',
                data: novelNames,
                axisLabel: {
                    interval: 0
                },
                axisPointer: {
                    type: 'shadow'
                }
            },
            yAxis: [
                {
                    type: 'value',
                    name: '章节数',
                    min: 0,
                    position: 'left'
                },
                {
                    type: 'value',
                    name: '每章平均字数',
                    min: 0,
                    position: 'right'
                }
            ],
            series: [{
                name: '章节数',
                type: 'bar',
                data: novelChapters,
                itemStyle: {
                    normal: {
                        color: '#00A0E9' // 设置颜色
                    }
                }
            },
                {
                    name: '每章平均字数',
                    type: 'line',
                    yAxisIndex: 1,
                    data: numAvgs,
                    smooth: true,
                    symbolSize: 10,
                    itemStyle: {
                        normal: {
                            color: '#FF0000', // 设置颜色
                            lineStyle: {
                                color: '#FF0000' // 设置折线颜色
                            }
                        }
                    }
                }]
        };
        if (option && typeof option === 'object') {
            myChart.setOption(option);
        }
    });
</script>
</body>
</html>
